#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年3月30日

@author: chenyongbing
'''
import sys,os,re
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]

from django import forms
from django.forms.util import ErrorList
import localConfig
#from  localConfig import LocalConfig

#     my_int_default_errors = {
#         'required': '该字段不能为空',
#         'invalid': '输入正确的数字类型'
#     }
#     my_email_default_errors = {
#         'required': '该字段不能为空',
#         'invalid': '输入正确的邮箱类型'
#     }
#     my_date_default_errors = {
#         'required': '该字段不能为空',
#         'invalid': '输入正确的日期类型yyyy-mm-dd'
#     }


#widget=forms.TextInput(attrs={'disabled':'disabled'}),

class ExportMacsForm(forms.Form):
    Roles_Choices = (('customer','顾客'),
                     ('new_customer','新顾客'),
                     ('old_customer','老顾客'),
                     ('walkby','路人'),
                     ('all','全部角色'),
             )
    MacType_Choices = (('all','全部'),
                       ('local','随机MAC'),
                       ('global','真实MAC'),
                       )
    
    company = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('company','请选择公司'),),label=u'公司')
    group = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('group','请选择门店'),),label=u'门店')
    province = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('province','请选择省份'),),label=u'省份')
    city = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('city','请选择城市'),),label=u'城市')
    dist = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('dist','请选择区域'),),label=u'区域')
    cate = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('cate','请选择类别'),),label=u'类别')
    startTime = forms.DateField(input_formats=(("%Y-%m-%d"),),label=u"开始时间",required=False)
    endTime = forms.DateField(input_formats=(("%Y-%m-%d"),),label=u"结束时间",required=False)
    rtype = forms.ChoiceField(choices=Roles_Choices,label=u'导出角色')
#     min_freq = forms.IntegerField(label=u'最小到访次数')
#     max_freq = forms.IntegerField(label=u'最大到访次数')
#     min_avg_freq = forms.IntegerField(label=u'最小平均停留时长(秒)')
#     max_avg_freq = forms.IntegerField(label=u'最大平均停留时长(秒)')
#     if_md5 = forms.ChoiceField(choices=MacType_Choices,label=u'MAC地址是否加密')
#     if_serial_number = forms.ChoiceField(choices=MacType_Choices,label=u'MAC地址是否添加序号')
    mtype = forms.ChoiceField(choices=MacType_Choices,label=u'MAC地址分类')
    
    
     
     
     
def get_rules_temp_choices(temp_type='hour'):
    reload(localConfig)
    temps_Choices = []
    myLocalConfig = localConfig.LocalConfig()
    rules = myLocalConfig.rules
    #print rules
    keys = rules.keys()
    keys.sort()
    
    for rule in keys:
        rvalues = rules[rule]
        name = rvalues['name']
        if not re.search(temp_type,rule):continue
        temps_Choices.append([rule,name])
    return temps_Choices
class ExportHourDataForm(forms.Form):
    
#     temps_Choices = (('temp1','模板一'),
#                      ('temp2','模板二'),
#                      ('temp3','模板三'),
#              )
    
    temps_Choices=get_rules_temp_choices(temp_type='hour')
    
    
    company = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('company','请选择公司'),),label=u'公司')
    group = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('group','请选择门店'),),label=u'门店')
    province = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('province','请选择省份'),),label=u'省份')
    city = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('city','请选择城市'),),label=u'城市')
    dist = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('dist','请选择区域'),),label=u'区域')
    cate = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=(('cate','请选择类别'),),label=u'类别')
    startTime = forms.DateField(input_formats=(("%Y-%m-%d"),),label=u"开始时间",required=False)
    endTime = forms.DateField(input_formats=(("%Y-%m-%d"),),label=u"结束时间",required=False)
    temp = forms.ChoiceField(widget=forms.Select(attrs={'class':'target'}),choices=temps_Choices,label=u'导出模板')